//
//  SamllPosterView.m
//  卢卡的时光网
//
//  Created by 卡神 on 15/7/26.
//  Copyright © 2015年 lok. All rights reserved.
//

#import "SamllPosterView.h"
#import "SmallCell.h"

@implementation SamllPosterView

#pragma mark -init function 

- (nonnull instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(nonnull UICollectionViewLayout *)layout {
    if (self = [super initWithFrame:frame collectionViewLayout:layout]) {
        self.delegate = self;
        self.dataSource = self;
        [self registerClass:[SmallCell class] forCellWithReuseIdentifier:@"smallCell"];
    }
    return self;
}

#pragma mark -collection's delegate and datasource

//实现点击左右cell滚动到其中心

- (void)collectionView:(nonnull UICollectionView *)collectionView didSelectItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    if (indexPath.row != self.currentIndex) {
        [self scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
        self.currentIndex = indexPath.row;
    }
}

- (UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    SmallCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"smallCell" forIndexPath:indexPath];
    cell.imageData = self.imageData[indexPath.row];
    return cell;
}


@end
